package com.usian.admin.controller.v1;

import com.usian.admin.service.AdChannelService;
import com.usian.api.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/*
* 频道管理的controller
* */
@RestController
@RequestMapping("/admin/api/v1/channel")
@Api(value = "频道管理",tags = "channel",description = "频道管理API")
public class AdchannelController implements AdChannelControllerApi {

    @Resource
    private AdChannelService adChannelService;
    /*
    *根据name查询对应的channel
    * */
    @PostMapping("/list")
    @Override
    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询频道列表")
    @ApiImplicitParam(name = "dto",type = "ChannelDto",value = "查询名称")
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return adChannelService.findByNameAndPage(dto);
    }

    @GetMapping("/del/{id}")
    @Override
    @ApiOperation(value = "删除")
    public ResponseResult deleteById(@PathVariable Integer id) {
        return adChannelService.deleteById(id);
    }
    @PostMapping("/save")
    @Override
    @ApiOperation("/添加")
    public ResponseResult insert(@RequestBody AdChannel adChannel) {
        return adChannelService.insert(adChannel);
    }
    @PostMapping("/update")
    @Override
    @ApiOperation("修改")
    public ResponseResult update(@RequestBody AdChannel adChannel) {
        return adChannelService.update(adChannel);
    }

    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        return ResponseResult.okResult(adChannelService.list());
    }
}
